package com.vgulu.server.common.mongodb;

import com.google.gson.annotations.SerializedName;
import org.bson.types.ObjectId;

/**
 * Created by wangchunsee on 2017/1/28.
 */
public class MongoId {

    /**
     * _id : dd
     */

    @SerializedName("_id")
    private ObjectId id;

    public String getId() {
        return id.toHexString();
    }

    public void setId(ObjectId id) {
        this.id = id;
    }
    public void setId(String id) {
        this.id = new ObjectId(id);
    }

    public int getTimestamp(){
        if (id!=null){
            return id.getTimestamp();
        }
        return (int)(System.currentTimeMillis()/1000);
    }
}
